package com.polytech.business;

import java.util.Collection;
import java.util.LinkedList;
import java.util.Set;
import java.util.Vector;

import com.polytech.beans.Booking;
import com.polytech.beans.Brand;
import com.polytech.beans.Car;
import com.polytech.beans.Category;
import com.polytech.beans.Color;
import com.polytech.beans.Model;
import com.polytech.dao.BrandDao;
import com.polytech.dao.CarDao;
import com.polytech.dao.CategoryDao;
import com.polytech.dao.ColorDao;
import com.polytech.dao.ModelDao;
import com.polytech.utils.BusinessFactory;

public class DefaultCarsManager implements CarsManager {

	private CarDao carDao;
	private ModelDao modelDao;
	private BrandDao brandDao;
	private CategoryDao categoryDao;
	private ColorDao colorDao;
	
	public void setColorDao(ColorDao colorDao) {
		this.colorDao = colorDao;
	}
	
	@Override
	public void create(Car car) {
		carDao.insert(car);
	}

	@Override
	public Car find(String key) {
		return carDao.select(key);
	}

	@Override
	public void remove(Car car) {
		carDao.remove(car);
	}

	@Override
	public void update(Car car) {
		carDao.insert(car);
	}

	public void setCarDao(CarDao carDao) {
		this.carDao = carDao;
	}
	
	public void setBrandDao(BrandDao brandDao) {
		this.brandDao = brandDao;
	}
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
	public void setModelDao(ModelDao modelDao) {
		this.modelDao = modelDao;
	}

	@Override
	public Collection<Car> getCars() {
		return carDao.selectAll();
	}

	@Override
	public Collection<Model> getModels() {
		return modelDao.selectAll();
	}

	@Override
	public Collection<Brand> getBrands() {
		return brandDao.selectAll();
	}

	@Override
	public Collection<Category> getCategories() {
		return categoryDao.selectAll();
	}



	@Override
	public Collection<Color> getColors() {
		return colorDao.selectAll();
	}



	@Override
	public Category findCategory(String key) {
		// TODO Auto-generated method stub
		return categoryDao.select(key);
	}



	@Override
	public void removeCategory(Category category) {
			categoryDao.remove(category);
	}



	@Override
	public void updateCategory(Category category) {
	
	}



	@Override
	public Model findModel(String key) {
		return modelDao.select(key);
	}



	@Override
	public void removeModel(Model model) {
		modelDao.remove(model);
	}



	@Override
	public void updateModel(Model model) {
		
	}



	@Override
	public Color findColor(String key) {
		return colorDao.select(key);
	}



	@Override
	public void removeColor(Color color) {

		colorDao.remove(color);
	}



	@Override
	public void updateColor(Color color) {
	}



	@Override
	public Brand findBrand(String key) {
		return brandDao.select(key);
	}



	@Override
	public void removeBrand(Brand brand) {
		brandDao.remove(brand);
	}



	@Override
	public void updateBrand(Brand brand) {
	}



	@Override
	public Collection<Car> getNonBookedCars() {
		return BusinessFactory.getReservationManager().getNonBookedCars();
	}



	@Override
	public Collection<Car> getBookedCars() {
		return BusinessFactory.getReservationManager().getBookedCars();
	}

	@Override
	public Set<Model> getModelsOf(String brand) {
		 Brand b = brandDao.select(brand);
		 if(b!=null){
			return b.getModels();
		 }
		return null;
				
	}
	@Override
	public void create(String plaque, String state, double km, String color,
			String picture, String model, String category, double price) {
		 Color color2=colorDao.select(color);
		 Model model2=modelDao.select(model);
		 Category category2=categoryDao.select(category);
		 Car car=new Car(plaque, state, km, color2, picture, model2, category2, price);
		 create(car);
	}
}
